package com.example.demo.controller;

import com.example.demo.model.Coffee;
import com.example.demo.service.CoffeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.AccessType;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@Controller
@RequestMapping("/coffee")
@Slf4j
public class CoffeeController {
    @Autowired
    private CoffeeService coffeeService;

//xml格式返回
    @RequestMapping(path = "/{id}", method = RequestMethod.GET,produces = MediaType.APPLICATION_XML_VALUE)
    @ResponseBody
    public Coffee getById(@PathVariable Long id) {
        Coffee coffee = coffeeService.findById(id);
        log.info("Coffee {}:", coffee);
        return coffee;
    }
//json格式返回
    @GetMapping(path = "/all",produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ArrayList<Coffee> getAll() {

        return coffeeService.findAll();
    }
}
